@echo off

setlocal enabledelayedexpansion

set /a is_err_if_lines=2

set info_m=
set /a ret=0
set v_new=export_after=


echo is_err_if_lines = %is_err_if_lines%

echo check gen sqls before dump is start... ...

if exist 1.err_counts del 1.err_counts

if not exist enable_triggers.log (
  echo enable_triggers.log does not exist, maybe enable_triggers dose not execute, plase check it.
  set info_m=with errors.
  set /a ret=-100
  goto finish 
)

if not exist exp_source.log (
  echo exp_source.log does not exist, maybe exp_source dose not execute, plase check it.
  set info_m=with errors.
  set /a ret=-100
  goto finish 
)

if not exist drop_type_number_array.log (
  echo drop_type_number_array.log does not exist, maybe drop_type_number_array dose not execute, plase check it.
  set info_m=with errors.
  set /a ret=-100
  goto finish 
)

for %%i in (enable_triggers.log,exp_source.log,drop_type_number_array.log) do (

set logfile=%%i
echo now check !logfile! ... ...

find /i "ORA-" !logfile! > 1.err_counts
set /a vars=0
echo init vars ::: !vars!
for /f %%j in (1.err_counts) do set /a vars=!vars!+1
echo accumulate vars ::: !vars!
if !vars! GEQ %is_err_if_lines% (goto dbscriptError_ex) else (del /q 1.err_counts)

find /i "SP2-" !logfile! > 1.err_counts
set /a vars=0
for /f %%j in (1.err_counts) do set /a vars=!vars!+1
if !vars! GEQ %is_err_if_lines% (goto dbscriptError_ex) else (del /q 1.err_counts)

find /i "PLS-" !logfile! > 1.err_counts
set /a vars=0
for /f %%j in (1.err_counts) do set /a vars=!vars!+1
if !vars! GEQ %is_err_if_lines% (goto dbscriptError_ex) else (del /q 1.err_counts)

find /i "IMP-" !logfile! > 1.err_counts
set /a vars=0
for /f %%j in (1.err_counts) do set /a vars=!vars!+1
if !vars! GEQ %is_err_if_lines% (goto dbscriptError_ex) else (del /q 1.err_counts)

find /i "EBER-" !logfile! > 1.err_counts
set /a vars=0
for /f %%j in (1.err_counts) do set /a vars=!vars!+1
if !vars! GEQ %is_err_if_lines% (goto dbscriptError_ex) else (del /q 1.err_counts)

find /i "DBERROR:" !logfile! > 1.err_counts
set /a vars=0
for /f %%j in (1.err_counts) do set /a vars=!vars!+1
if !vars! GEQ %is_err_if_lines% (goto dbscriptError_ex) else (del /q 1.err_counts)

find /i """O/S Message:""" !logfile! > 1.err_counts
set /a vars=0
for /f %%j in (1.err_counts) do set /a vars=!vars!+1
if !vars! GEQ %is_err_if_lines% (goto dbscriptError_ex) else (del /q 1.err_counts)
)

:succ_1
echo enable_triggers.sql,exp_source.sql,drop_type_number_array.sql  completed ... ...
set info_m=without errors.
set /a ret=100
goto finish

:dbscriptError_ex
echo !logfile! has errors.
set info_m=with errors.
set /a ret=-100

:finish
echo finish !info_m!
exit !ret!

endlocal